﻿@model RoleModel
@{
    var role = Model.Role;
    var modules = Model.ModuleCategories;
}
<div class="layui-card">
    <div class="layui-card-header">当前分配角色：@role.Name</div>
    <div class="layui-card-body">
        <form class="layui-form" action="" id="r" name="r">
            @foreach (var item in modules)
            {
                <input type="hidden" name="roleId" value="@role.RoleID" />
                <div class="layui-form-item">
                    <label class="layui-form-label">@item.CategoryName</label>
                    <div class="layui-input-block">
                        @foreach (var item1 in item.Modules.OrderBy(x=>x.ModuleID))
                        {
                            var check = "";
                            if (role.Modules.Any(x => x.ModuleID == item1.ModuleID))
                            {
                                check = "checked";
                            }

                            <input @check type="checkbox" value="@item1.ModuleID" name="modules" title="@item1.Name">

                        }
                    </div>

                </div>
            }
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="role-save">
                        <i class="layui-icon layui-icon-ok"></i>
                        提交
                    </button>
                    <button type="reset" class="pear-btn pear-btn-sm">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
@section script{
    <script>
        layui.use(['form', 'layer'], function () {
            var form = layui.form;
            var $ = layui.jquery;
            var layer = layui.layer;
            form.on('submit(role-save)', function (data) {
                //layer.msg(JSON.stringify(data.field));
                $.post("/role/fmodule", $("#r").serialize(), function (res) {
                    if (res.success) {
                        layer.msg(res.msg, { icon: 1, time: 100000 }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            //parent.layui.table.reload("role-table");
                        });
                    } else {
                        layer.msg(result.msg, { icon: 2, time: 1000 });
                    }

                })
                return false;
            });
        });
    </script>
}